package com.example.transaction.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.transaction.sys.entity.Classfy;
import com.example.transaction.sys.entity.Comment;
import com.example.transaction.sys.mapper.CommentMapper;
import com.example.transaction.sys.mapper.ItemMapper;
import com.example.transaction.sys.mapper.UserMapper;
import com.example.transaction.sys.service.ICommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.transaction.sys.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zh
 * @since 2023-06-20
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {

    @Autowired
    private IUserService userService;

    @Autowired
    private ItemMapper itemMapper;

    public List<Integer> getItemIdsByUsernameLike(String sellerName) {
        // 根据卖家名称模糊查询用户ID列表
        List<Integer> userIds = userService.getUserIdsByUsernameLike(sellerName);

        if (userIds.isEmpty()) {
            return Collections.emptyList();
        }

        // 根据用户ID列表查询商品ID列表
        List<Integer> itemIds = itemMapper.getItemIdsByUserIds(userIds);

        return itemIds;
    }

    @Override
    public List<Comment> getCommentByUserID(String userid) {
        LambdaQueryWrapper<Comment> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Comment::getUserID, userid);
        List<Comment> commentList = list(wrapper);

        List<Comment> comments = new ArrayList<>();
        for (Comment comment : commentList) {
            comments.add(comment);
        }

        return comments;
    }

    @Override
    public List<Comment> getCommentByUserName(String username) {
//        LambdaQueryWrapper<Comment> wrapper = new LambdaQueryWrapper<>();
//        List<Comment> commentList = list(wrapper);
//
//        List<Comment> comments = new ArrayList<>();
//        for (Comment comment : commentList) {
//            comments.add(comment);
//        }
//
//        return comments;
        return null;
    }
}
